<template>
    <div class="main">
        <div class="container">
            <!-- 搜索框 -->
            <div class="search">
                <input class="input" placeholder="输入搜索内容..." @click="showPanel = !showPanel" />
            </div>
            <!-- 遮罩层 -->
            <div class="overlay" v-if="!showPanel" @click="showPanel = !showPanel"></div>
            <!-- 八个按钮：圆形、阴影、边框 -->
            <div class="image">
                <div>订票</div>
                <div>酒店</div>
                <div>美食</div>
                <div>导航</div>
                <div>购物</div>
                <div>求助</div>
                <div>社交</div>
                <div>翻译</div>
            </div>

            <div class="slider">
                <div class="sliderBox" m="t-2">
                    <el-carousel trigger="click" height="300px" :autoplay="true" :interval="3000">
                        <el-carousel-item v-for="item in itemList" :key="item.id">
                            <h3 class="small justify-center" text="2xl">
                                <img :src="item.imageUrl" :alt="item.title || '轮播图'">
                            </h3>
                        </el-carousel-item>
                    </el-carousel>
                </div>
            </div>
            <!-- 上图下文 -->
            <div class="text">推荐景点</div>
            <Img />
            <!-- 卡片 -->
            <div class="text">收藏最多</div>
            <ImageText :information="historyData" />

            <!-- 客服 -->
            <div class="buyCart">
                <img src="../../assets/img/robert.webp" alt="购物车" @click="openCart" />
            </div>

        </div>
    </div>
</template>

<script setup>
import ImageText from '../../components/ImgText.vue';
import Img from '../../components/Img.vue'
import { onMounted, ref } from 'vue'
import axios from 'axios';

const itemList = ref([]);
const url = 'http://localhost:3000/TokyoSpots/'
const showPanel = ref(false);

// 历史记录数据
const historyData = ref({
    url: 'http://localhost:3000/TokyoSpots/',
    title: '浏览记录',
    items: [] // 实际项目中可以从API获取
});

onMounted(() => {
    axios.get(url)
        .then(response => {
            itemList.value = response.data;
        })
        .catch(error => {
            console.error('Error fetching items:', error);
        });
});
</script>

<style lang="css" scoped>
.main {
    margin-bottom: 100px;
    padding: 20px;
    max-width: 430px;
    margin: 0 auto;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    margin-bottom: 100px;
}

.container {
    background-color: rgba(255, 249, 241, 0.9);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* 搜索框样式 */
.search {
    display: flex;
    justify-content: center;
    margin: 20px 0 30px;
}

.input {
    width: 100%;
    max-width: 350px;
    height: 40px;
    border-radius: 20px;
    border: 1px solid #ddd;
    padding: 0 20px;
    font-size: 16px;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.input:focus {
    border-color: #aa4caf;
    box-shadow: 0 2px 12px rgba(76, 175, 80, 0.2);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* 半透明黑色 */
    z-index: 1000;
    /* 确保在顶层 */
    display: none;
    /* 默认隐藏 */
}

/* 圆形按钮区域 */
.image {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin: 30px 0;
    object-fit: cover;
}

.image div {
    background: linear-gradient(135deg, #ddeaff 0%, #d1e3ff 100%);
    width: 70px;
    height: 0px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: #333;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    margin: 0 auto;
}

.image div:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* 轮播图样式 */
.slider {
    margin: 40px 0;
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
}

.el-carousel {
    border-radius: 12px;
}

.el-carousel__item h3 {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    margin: 0;
}

.el-carousel__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 标题样式 */
.text {
    background: linear-gradient(90deg, #a6dea8, #8BC34A);
    color: white;
    font-size: 20px;
    font-weight: 600;
    padding: 12px 20px;
    margin: 40px 0 20px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.2);
    position: relative;
}

.text::after {
    content: "";
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background-color: white;
    border-radius: 3px;
}

/* 客服按钮 */
.buyCart {
    position: fixed;
    bottom: 90px;
    right: 30px;
    width: 60px;
    height: 60px;
    background-color: #4CAF50;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(30, 30, 30, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 100;
}

.buyCart:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(30, 30, 30, 0.4);
}

.buyCart img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

/* 响应式调整 */
@media (max-width: 480px) {
    .image {
        grid-template-columns: repeat(4, 1fr);
        gap: 15px;
    }

    .image div {
        width: 60px;
        height: 60px;
        font-size: 14px;
    }

    .text {
        font-size: 18px;
        margin: 30px 0 15px;
    }

    .slider {
        margin: 30px 0;
    }

    .buyCart {
        width: 50px;
        height: 50px;
        bottom: 80px;
        right: 20px;
    }

    .buyCart img {
        width: 30px;
        height: 30px;
    }
}
</style>